const addLabel = (label,val,storageName)=>{
	let sameValIndex = label.findIndex( item => item === val )
	if(sameValIndex !== -1){
		label.splice(sameValIndex,1)
		label.unshift(val)
	}else{
		label.unshift(val)
	}
	uni.setStorageSync(storageName,label)
}

const delLabel = (label,val,storageName)=>{
	label.splice(label.findIndex(item=>item===val),1)
	uni.setStorageSync(storageName,label)
}

export default {
  state: {
	postLabel:uni.getStorageSync('postLabel') || [],
	goodsLabel:uni.getStorageSync('goodsLabel') || []
  },
  mutations: {
	givePostLabel(state,val){
		addLabel(state.postLabel,val,'postLabel')
	},
	giveGoodsLabel(state,val){
		addLabel(state.goodsLabel,val,'goodsLabel')
	},
	delPostLabel (state, val) {
	  delLabel(state.postLabel, val, 'postLabel')
	},
	delGoodsLabel (state, val) {
	  delLabel(state.goodsLabel, val, 'goodsLabel')
	},
	delBothPostLabel (state) {
	  state.postLabel = []
	  uni.removeStorageSync('postLabel')
	},
	delBothGoodsLabel (state) {
	  state.goodsLabel = []
	  uni.removeStorageSync('goodsLabel')
	}
  },
  actions: {
  }
}